---@class load 加载器
load = OrderedTable()
---@type table<number,{text:string,call:load_call}> 存储器
load.call = OrderedTable()

---@alias load_call fun():void

Loding = nil
---添加加载
---@param data {text:string,call:load_call}
function load.add(data)
    table.insert(load.call, data)
end

---开始加载
function load.loding()
    local index = 1
    local count = #load.call
    Loding = new(GT.ui.model.loding)
    Loding:set_max(count)
    Loding:set_text('等待加载')
    GT.timer.obj({
        count = 1,
        delay = 0.5,
        immediately = false,
        callback = function()
            for index, value in ipairs(load.call) do
                workQueue:enqueue(function()
                    Loding:set_text(value.text)
                    value.call()
                    
                    index = index + 1
                    if index > count then
                        
                        Loding:set_text('加载完成!')
                        Loding:hide()
                    end
                    Loding:set_cur(index)
                end)
            end
        end
    })

    -- while index <= count do
    --     local tump = load.call[index]
    --     tump.call()
    --     GT.ui.model.sysMsgTip.obj({
    --         text = tump.text .. index .. '/' .. count,
    --         prefix = '加载系统'
    --     })
    --     index = index + 1
    --     if index > count then
    --         GT.ui.model.sysMsgTip.obj2('加载完成')
    --     end
    -- end
end
